package cn.edu.suda.schoolBus.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.edu.suda.schoolBus.bean.DepartureInfo;
import cn.edu.suda.schoolBus.service.DepartureInfoService;
import cn.edu.suda.schoolBus.util.ResultUtil;
import cn.edu.suda.schoolBus.util.ScheduleUtil;

@Controller
public class DepartureInfoController {

	@Autowired
	private DepartureInfoService departureInfoService;

	@RequestMapping("/addDepartureInfo")
	@ResponseBody
	public Map<String, Boolean> addDpartureInfo(DepartureInfo departureInfo) {
		Map<String, Boolean> map = ResultUtil.getResult(departureInfoService.addDepartureInfo(departureInfo));
		if (map.get("flag")) {
			ScheduleUtil.editDriver(departureInfo.getRelateToDriver());
			ScheduleUtil.editSchoolBus(departureInfo.getRelateToSchoolBus());
		}
		return map;
	}

	@RequestMapping({ "/getDepartureInfo", "/client/getDepartureInfo" })
	@ResponseBody
	public List<DepartureInfo> getdDpartureInfo(int dcnId) {
		return departureInfoService.getDepartureInfo(dcnId);
	}

	@RequestMapping("/statisticsSchoolBus")
	@ResponseBody
	public Map<String, Object> statisticsDpartureInfo(int days) {
		return departureInfoService.statisticsSchoolBus(days);
	}

}
